package com.threeonemeeting.activity;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.mobclick.android.MobclickAgent;
import com.snda.lib.util.ImageDownloader;
import com.snda.lib.util.ImageHelper;
import com.threeonemeeting.R;
import com.threeonemeeting.util.AppSettings;

public class PreviewImageActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ac_image_view);

		final String strUrl = getIntent().getExtras().getString("url");

		ImageDownloader.Callback wrapCallback = new PreviewImageLoadedCallback();
		Bitmap bm = ImageDownloader
				.loadImage(getApplicationContext(), strUrl,
						AppSettings.getImagePath(getApplicationContext()),
						wrapCallback);
		if (bm != null) {
			wrapCallback.imageLoaded(bm, strUrl);
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	class PreviewImageLoadedCallback implements ImageDownloader.Callback {

		public PreviewImageLoadedCallback() {
		}

		public void imageLoaded(Bitmap arg0, String arg1) {
			LinearLayout loadingLayout = (LinearLayout) findViewById(R.id.loading_layout);
			ImageView image = (ImageView) findViewById(R.id.image);
			loadingLayout.setVisibility(View.GONE);
			image.setVisibility(View.VISIBLE);

			image.setBackgroundDrawable(ImageHelper.bitmap2Drawable(arg0));
		}
	}
}